package transfer;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/14
 */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class LoginTest {
    public static boolean login(String username, String password) {
        try (
                //获取与指定的类同级目录下的流对象
                InputStream is = LoginTest.class.getResourceAsStream("emp.txt");
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr)
        ) {
            String s=null;
            while ((s = br.readLine()) != null) {
                String[] parts = s.split("#");
                if ( username.equals(parts[0]) && password.equals(parts[1])) {
                    return true;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        boolean result = login("李四", "123");
        if(result){
            System.out.println("登录成功！");
        }else{
            System.out.println("登录失败！");
        }
    }
}